/* 被观察者 */
#pragma once
#ifndef __OBSERVED__
#define __OBSERVED__

#include <vector>

#include "ObserverDog.h"
#include "ObserverMouse.h"

class Cat {
public:
    // 注册观察者
    void attach(AbstractObserver* observer) { observers_.push_back(observer); }

    // 注销观察者
    void detach(AbstractObserver* observer) {
        for (auto it = observers_.begin(); it != observers_.end(); ++it) {
            if (*it == observer) {
                observers_.erase(it);
                break;
            }
        }
    }

    // 通知观察者
    void notify() {
        std::cout << "there is a cat\n";
        for (auto ob : observers_) {
            ob->response();
        }
    }

private:
    std::vector<AbstractObserver*> observers_;
};

#endif